import io.qt.core.QEvent
import io.qt.core.QFile
import io.qt.core.QIODeviceBase
import io.qt.core.QSize
import io.qt.widgets.QFrame

class MainWindow : FrameLessMainWindow() {

    val ui = Ui_MainWindow()

    init {
        ui.setupUi(this)
        this.initWindow()
    }

    private fun initWindow() {
        ui.labTitle?.text = "MusicPlayer"
        this.windowTitle = "Kotlin-Qt-Music-Player"
        ui.labTitle?.let { this.setTitleBar(it) }

        //关联信号
        this.titleDblClick.connect(titleDblClick)
        this.windowStateChange.connect(windowStateChange)
        //设置样式表
        val styleFile = QFile(":/css/style.css")
        styleFile.open(QIODeviceBase.OpenModeFlag.ReadOnly)
        this.styleSheet = styleFile.readAll().toString()
        styleFile.close()

        ui.left_menu?.frameShape = QFrame.Shape.NoFrame
        ui.left_menu?.iconSize = QSize(24, 24)
    }

    override fun changeEvent(e: QEvent?) {
        super.changeEvent(e)
        when (e?.type()) {
            QEvent.Type.LanguageChange -> ui.retranslateUi(this)
            else -> {}
        }
    }
}
